package com.yihukurama.sysbase.framework.domainservice;

import com.yihukurama.base.app.exception.TipsException;
import com.yihukurama.base.app.utils.EmptyUtil;
import com.yihukurama.base.app.utils.LogUtil;
import com.yihukurama.sysbase.framework.entity.MenuEntity;
import net.bytebuddy.pool.TypePool;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import com.yihukurama.base.framework.service.domainservice.CrudService;

import java.util.List;

/**
 * 说明： Menu的领域服务
 * @Author: yihukurama
 */
@Service
public class MenuService extends CrudService<MenuEntity>{


    @Override
    public int remove(MenuEntity menuEntity) throws TipsException {
        //查询下级，若有下级则不可删除

        String pid = menuEntity.getId();
        MenuEntity childrenMenu = new MenuEntity();
        childrenMenu.setParentId(pid);
        List<MenuEntity> childrenList = list(childrenMenu);
        if (!EmptyUtil.isEmpty(childrenList)){
            throw new TipsException("菜单仍有下级，请先删除下架");

        }


        return super.remove(menuEntity);
    }
}
